using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Antlr.Runtime.Tree;
using Antlr.Runtime;

namespace NeuroSpeech.Imap
{
	public class ImapResponseSelect : BaseImapResponse
	{

		public int Total { get; set; }

		public int Recent { get; set; }

		public ulong UIDValidity { get; set; }

		public ulong UIDNext { get; set; }

		#region public override void  Process(ImapClient client)
		public override void Process(ImapClient client)
		{
			base.Process(client);

			foreach (var item in Lines)
			{
				var tree = Parse(item);
				if (tree.ChildCount == 3 && tree.GetChild(2).Text.ToLower() == "exists")
				{
					Total = int.Parse(tree.GetChild(1).Text);
				}
				if (tree.ChildCount == 3 && tree.GetChild(2).Text.ToLower() == "recent")
				{
					Recent = int.Parse(tree.GetChild(1).Text);
				}
				if (tree.ChildCount>2 && tree.GetChild(2).Text == "[") {
					var c = tree.GetChild(2);
					if (c.ChildCount==2 && c.GetChild(0).Text.ToLower() == "uidvalidity") {
						ulong n = 0;
						string txt = c.GetChild(1).Text;
						ulong.TryParse(txt, out n);
						UIDValidity = n;
					}
					if (c.ChildCount == 2 && c.GetChild(0).Text.ToLower() == "uidnext") {
						ulong n = 0;
						string txt = c.GetChild(1).Text;
						ulong.TryParse(txt, out n);
						UIDNext = n;
					}
				}
			}
		}
		#endregion


	}
}
